/**
 * Created by gdg on 2017/5/7.
 */
import {observable, action} from 'mobx'

class DomainStore {
	@observable fetched = '空';//监听的对象,当对象的值发生变化自动重新渲染页面
	@observable username = '';
	@action.bound //改变监听对象的值
	fetch() {
		fetch('https://facebook.github.io/react-native/movies.json')
		.then((response) => response.json())//接收响应是异步的
		.then((responseJson) => {
			//网络请求响应完毕,修改监听对象的值
			this.fetched = JSON.stringify(responseJson.movies);
		})
		.catch((error) => {
			this.fetched = 'network error';
			console.error(error);
		});
	}

	@action.bound
	async login(username, password) {
		/*登录账号密码*/
		this.username = username;
		return true
		/*返回登录结果*/
	}
}

export default DomainStore;